package likou.tanxin;

/**
 * @Info:
 * @Author: Tangxz
 * @Date: 2020/09/10 18:48
 */
public class _55 {
    public static void main(String[] args) {
        System.out.println(canJump(new int[]{1,2}));
    }
    public static boolean canJump(int[] nums) {
        int nextIndex = 0;
        int nowIndex = 0;
        int step = nums[0]+nowIndex;
        while(nowIndex<nums.length){
            if(step<=nextIndex&&nextIndex!=nums.length-1){
                return false;
            }
            nowIndex++;
            while(nowIndex<nums.length&&nowIndex<step){
                nextIndex = Math.max(nextIndex,nowIndex + nums[nowIndex]);
                nowIndex++;
            }
            if(nextIndex==nums.length-1||nowIndex>=nums.length-1){
                return true;
            }
            nowIndex = nextIndex;
            step = nextIndex+nums[nextIndex];
        }
        return true;
    }
}
